var app = getApp();
const domainUrl = app.globalData.domainUrl
var utils = require('../../utils/util.js')

Page({
  data: {
    scrollHeight: 569,
    imageWidth: 250,
    imageHeight: 250,
    photoList: [],
    total:0,
    total6:0
  },
  previewPhoto: function(event) {
    console.log(event);
    var curTarget = event.target.dataset.imageSrc;
    console.log(curTarget);
    wx.navigateTo({
      url: '../preview/preview?imagepath=' + curTarget
    })
  },
  twoColomn: function() {
    var that = this;
    var length = 750 / 2;
    that.setData({
      imageWidth: length,
      imageHeight: length * 360 / 250
    });
  },
  threeColomn: function() {
    var that = this;
    var length = 750 / 3;
    that.setData({
      imageWidth: length,
      imageHeight: length * 360 / 250
    });
  },
  fourColomn: function() {
    var that = this;
    var length = 750 / 4;
    that.setData({
      imageWidth: length,
      imageHeight: length * 360 / 250
    });
  },
  onLoad: function() {
    utils.login(this.route);
    console.log("加载照片列表");
    var that = this;
    // 获取当前窗口高度，以便设置scrollView的高度
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          scrollHeight: res.windowHeight + 8
        });
      }
    });
    var openid = wx.getStorageSync('my_openid');
    console.log("=========" + openid);
    wx.request({
      url: domainUrl+'shuihuCardListById?openId='+openid,
      success: function(res) {
        console.log(res);
        that.setData({
          photoList: res.data.urls,
          total: res.data.total,
          total6: res.data.total6
        })
      }
    });
    var that = this;
    var length = 750 / 3;
    that.setData({
      imageWidth: length,
      imageHeight: length * 360 / 250
    });
  },
  duihuan: function () {
    var that = this;
    var openid = wx.getStorageSync('my_openid');
    wx.showModal({
      title: '提示',
      content: '您要使用108将来兑换一个六大恶人么？',
      success: function (sm) {
        if (sm.confirm) {
          wx.request({
            url: domainUrl + 'shuihuCardDuihuan?openId=' + openid,
            success: function (res) {
              console.log(res.data);
              wx.showToast({
                title: '兑换成功',
                icon: 'success',
                duration: 2000,
                mask: false
              })
            }
          });
        } else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    });
    wx.request({
      url: domainUrl + '/shuihuCardListById?openId=' + openid,
      success: function (res) {
        console.log(res);
        that.setData({
          photoList: res.data.urls,
          total: res.data.total,
          total6: res.data.total6
        })
      }
    });
  },
  onShow: function() {
    console.log("显示图片")
    var that = this;
    var openid = wx.getStorageSync('my_openid');
    wx.request({
      url: domainUrl+'/shuihuCardListById?openId='+openid,
      success: function(res) {
        console.log(res);
        that.setData({
          photoList: res.data.urls,
          total: res.data.total,
          total6: res.data.total6
        })
      }
    });
  }
})